<template>
  <div>
    <!-- 车辆详情 -->
    <el-drawer
      v-if="visible"
      :visible.sync="visible"
      :with-header="false"
      direction="rtl"
    >
      <div class="title">
        <div class="title-left">
          <div class="title-text">{{ '采购详情' }}</div>
        </div>
        <div><span class="el-icon-close close-btn" @click="reset" /></div>
      </div>
      <div class="popups-info">
        <div class="left">
          <div class="info-title">基本信息</div>
          <el-descriptions size="medium" :column="3" :label-style="labelStyle" :content-style="contentStyle">
            <el-descriptions-item label="车牌号">{{ temp.licensePlate }}</el-descriptions-item>
            <el-descriptions-item label="司机">{{ temp.driver }}</el-descriptions-item>
            <el-descriptions-item label="燃气类型">{{ temp.purchaseType === 1 ? '液化气' : '丙烷' }}</el-descriptions-item>
            <el-descriptions-item label="卸车前车辆毛重(kg)">{{ temp.weightBefore }}</el-descriptions-item>
            <el-descriptions-item label="卸车后车辆毛重(kg)">{{ temp.weightAfter }}</el-descriptions-item>
            <el-descriptions-item label="实际卸货量(kg)">{{ temp.totalWeight }}</el-descriptions-item>
            <el-descriptions-item label="出厂单价(kg/元)">{{ temp.unitPrice }}</el-descriptions-item>
            <el-descriptions-item label="运费(kg/元)">{{ temp.freight }}</el-descriptions-item>
            <el-descriptions-item label="采购站点">{{ temp.purchaseOrgName }}</el-descriptions-item>
            <el-descriptions-item label="采购日期">{{ temp.purchaseDt && dayjs(temp.purchaseDt).format('YYYY-MM-DD') }}</el-descriptions-item>
            <el-descriptions-item :span="12" label="是否算运费">{{ temp.iscalculateFreight === 1 ? '是' : '否' }}</el-descriptions-item>
            <el-descriptions-item :span="12" label="备注"><span class="remark-desc">{{ temp.remark }}</span></el-descriptions-item>
          </el-descriptions>
          <div v-if="temp.attachmentInfoList && temp.attachmentInfoList.length > 0" class="signature">
            <div class="item-title">附件</div>
            <div>
              <el-image v-for="item in temp.attachmentInfoList" :key="item.id" class="image" :src="item.url" :preview-src-list="[item.url]" />
            </div>
          </div>
        </div>
        <!-- 右侧 -->
        <div class="right">
          <div class="timeline-title">操作日志</div>
          <el-timeline>
            <el-timeline-item v-for="(item, index) in turnoverList" :key="index" :timestamp="`${parseTime(item.operateTime, '{y}-{m}-{d} {h}:{i}')} ${item.createUser}`" placement="top">
              <el-card>
                <h4 v-if="item.operateUserName && item.operateDesc">{{ item.operateUserName +' '+ item.operateDesc }}</h4>
                <p>{{ `发生部门&nbsp;——&nbsp;${item.operateOrgName ? item.operateOrgName : '系统'}` }}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </div>
      </div>
      <div class="demo-drawer__footer">
        <el-button @click="visible = false"> 关闭 </el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  import { parseTime } from '@/utils'
  import dayjs from 'dayjs'
  import { queryAttachList, purchaseQueryLogList } from '@/api'
  export default {
    name: 'purchaseDetail', // 采购详情
    props: {
    },
    data() {
      return {
        visible: false,
        title: { 'color': '#38BDBD' },
        labelStyle: { 'white-space': 'nowrap' },
        contentStyle: { 'word-break': 'break-all' },
        temp: {},
        turnoverList: [], // 流转列表
        activeNames: ['1', '2']
      }
    },
    created() {

    },
    methods: {
      dayjs,
      parseTime,
      // 获取页面数据
      async  getPageInfo(row) {
        const res = await purchaseQueryLogList({ serviceType: 1, operationCode: row.purchaseCode })
        this.turnoverList = res.data || []
      },
      async open(temp) {
        return new Promise(async resolve => {
          this.resolve = resolve
          await this.getPageInfo(temp)
          if (temp.picIds) {
            const res = await queryAttachList({ picIds: temp.picIds })
            temp.attachmentInfoList = res.data || []
          }
          this.temp = { ...temp }
          this.visible = true
        })
      },
      showVideo() {
        this.$refs.vehicleVideo.open()
      },
      // 关闭
      reset() {
        this.temp = {}
        this.visible = false
      }
    }
  }
</script>

<style lang="scss" scoped>
/deep/.el-drawer {
  width: 80% !important;
}
/deep/.el-collapse-item__header {
  font-size: 16px;
  color: #38BDBD;
}
.title {
  position: fixed;
  display: flex;
  justify-content: space-between;
  width: 80%;
  padding: 20px 20px 20px 20px;
  background-color: white;
  .title-left {
    display: flex;
    .title-text {
      line-height: 25px;
    }
    .tag {
      margin: 0 10px;
    }
  }
  .close-btn {
    font-size: 20px;
    cursor: pointer;
  }
}
.popups-info {
  display: flex;
  height: calc(100vh - 120px);
  padding: 0 30px;
  margin-top: 70px;
  overflow-y: auto;
  .left {
    width: 75%;
    height: 100%;
    .info-title {
      margin-bottom: 10px;
      font-size: 16px;
      font-weight: 600;
      color: #38BDBD;
    }
    .signature {
      .item-title {
        margin-bottom: 10px;
        font-weight: 600;
        color: #38BDBD;
      }
      .image {
        width: 120px;
        height: 150px;
        padding: 10px 0;
        margin-right: 15px;
      }
    }
  }
  .right {
    height: 100%;
    padding-left: 15px;
    border-left: 1px solid #e3e3e3;
    flex: 1;
    .timeline-title {
      width: 100%;
      padding: 8px;
      margin-bottom: 10px;
      color: white;
      background-color: #38BDBD;
      border-radius: 5px;
    }
    .el-timeline {
      margin-top: 20px;
    }
  }
}
.demo-drawer__footer {
  position: fixed;
  bottom: 0;
  display: flex;
  align-items: center;
  width: 100%;
  height: 55px;
  padding-left: 10px;
  background: white;
  border: 1px solid #DCDFE6;
}
</style>
